package Test;

import java.util.Stack;

public class MinStack {

    Stack<Node> stack;
    public MinStack() {
        stack = new Stack<>();
    }

    public void push(int x) {
        if(stack.empty())
            stack.push(new Node(x, x));
        else
            stack.push(new Node(x, Math.min(x,stack.peek().min)));
    }

    public void pop() {
        stack.pop();
    }
    public int top(){
        return stack.peek().val;
    }

    public Integer getMin(){
        return stack.peek().min;
    }
    private static class Node{
        private int val;
        private int min;
        public Node(int val,int min){
            this.val = val;
            this.min = min;
        }
    }


}
